package com.fjec.im.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.common.protocol.JsonResult;
import com.fjec.im.service.IBizUserConversationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 012.用户会话表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/")
public class BizUserConversationController {

    @Resource
    private IBizUserConversationService service;

    /**
     * 获取会话列表
     *
     * @param page
     * @return
     */
    @GetMapping("/y/im/conv/list")
    public JsonResult getConvList(Page page) {
        return service.getConvList(page);
    }

    /**
     * 创建或获取会话信息
     *
     * @param toId     会话对方userId
     * @param busiType
     * @param shopName
     * @return
     */
    @PostMapping("/y/im/conv/create/or/get")
    public JsonResult createOrGetConversation(Long toId, Integer busiType, String shopName) throws Exception {
        return service.createOrGetConversation(toId, busiType, shopName);
    }

    /**
     * 根据Id获取会话信息
     *
     * @param id 会话Id
     * @return
     */
    @GetMapping("/y/im/conv/get")
    public JsonResult getConversation(Long id) {
        return service.getConversation(id);
    }

    /**
     * 根据Id获取并更新会话
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/y/im/get/and/update/conv")
    public JsonResult getAndUpdateConversation(Long id) throws Exception {
        return service.getAndUpdateConversation(id);
    }
}
